package test.yzx.pproject.act3;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.FrameLayout;

import test.yzx.pproject.R;

public class ZhuanQuanView extends FrameLayout{

    public ZhuanQuanView(Context context) {
        this(context, null);
    }
    public ZhuanQuanView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }
    public ZhuanQuanView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        final View icon = LayoutInflater.from(context).inflate(R.layout.view_zq, this, true).findViewById(R.id.iv_icon);

        post(new Runnable() {
            public void run() {
                ObjectAnimator anim = ObjectAnimator.ofFloat(ZhuanQuanView.this, "rotation", 0f, 360f).setDuration(1600);
                anim.setRepeatCount(Integer.MAX_VALUE);
                anim.setStartDelay(0);
                anim.setInterpolator(new LinearInterpolator());
                anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    public void onAnimationUpdate(ValueAnimator animation) {
                        float now = (float) animation.getAnimatedValue();
                        icon.setRotation(-now);
                    }
                });
                anim.start();
            }
        });
    }


    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, widthMeasureSpec);
    }

}
